package cn.stronglink.assetmanage.business.setting.ipset;

import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewPager;
import android.view.View;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.stronglink.assetmanage.MyApplication;
import cn.stronglink.assetmanage.R;

/**
 * @author zww
 * 2018 2018/6/17 21:16
 */
public class SystemSettingView {
    @BindView(R.id.tbSysConfig)
    TabLayout tbSysConfig;
    @BindView(R.id.vpSysConfig)
    ViewPager vpSysConfig;

    private SystemViewPagerAdapter vpAdapter;
    private FragmentManager fm;

    private Fragment fragment;
    private String[] mTitle = MyApplication.APP_CONTEXT.getResources().getStringArray(R.array.setting);

    SystemSettingView(Fragment fragment, View view) {
        this.fragment = fragment;
        ButterKnife.bind(this, view);
        initView();
    }

    private void initView() {
        //fm = fragment.getActivity().getSupportFragmentManager();
        fm = fragment.getChildFragmentManager();
        vpAdapter = new SystemViewPagerAdapter(fm, mTitle);
        vpSysConfig.setAdapter(vpAdapter);
        tbSysConfig.setupWithViewPager(vpSysConfig);
        tbSysConfig.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                vpSysConfig.setCurrentItem(tab.getPosition());
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {

            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }
}
